<?php

namespace app\common\model\mysql;

use think\Model;

class SGoodsCategory extends Model
{
    //批量插入商品与类型关联表数据
    public function insertAllGoodsCategory($categoryIds,$goodsId,$order_num=0){
        $data = [];
        foreach ($categoryIds as $categoryId) {
            $order_num++;
            $data[] = [
                'category_id' => $categoryId,
                'goods_id' => $goodsId,
                'order_num'=>$order_num,
            ];
        }
        return $this->insertAll($data);
    }

    /**
     * 删除商品图片数据信息
     * @param $ids
     * @return bool
     */
    public function deleteCategoryIds($id){
        if(empty($id)){
            return false;
        }
        $where = [
            ['goods_id', '=', $id]
        ];
        $result = $this->where($where)->delete();
        return $result;
    }

    public function getNormalGoodsFieldList($where,$field){
        $order = [
            "order_num" =>"asc",
        ];
        $result = $this->where($where)->order($order)->column($field);
        return $result;
    }
}
